from django.db import models

# Create your models here.

class Account(models.Model):
    sex_choice = (
        ('1','男'),
        ('2','女')
    )
    status_choice = (
        ('1','正常'),
        ('2','封号')
    )
    username = models.CharField(max_length=15,null=True,verbose_name='账号')
    password = models.CharField(max_length=15,null=True,verbose_name='密码')
    mobile = models.CharField(max_length=13,null=True,verbose_name='手机号')
    nick_name = models.CharField(max_length=5,null=True,verbose_name='姓名')
    sex = models.CharField(max_length=1,null=True,verbose_name='性别',choices=sex_choice)
    created_time = models.DateTimeField(auto_now_add=True,verbose_name='建立账号时间')
    status =models.CharField(max_length=1,null=True,verbose_name='账号状态',choices=status_choice)
    description = models.CharField(max_length=200,null=True,verbose_name='描述')
    class Meta:
        db_table = 'movie_account'

class Douban_Movie(models.Model):
    choices = (
        ('1','热门'),
        ('2','正在上映')
    )
    title = models.CharField(max_length=20,null=True,verbose_name='电影名')
    types = models.CharField(max_length=50,null=True,verbose_name='电影类型（数组）')
    actors = models.CharField(max_length=100,null=True,verbose_name='电影演员（数组）')
    regions = models.CharField(max_length=50,null=True,verbose_name='电影产地（数组）')
    release_date = models.CharField(max_length=20,null=True,verbose_name='电影上映时间')
    score = models.CharField(max_length=5,null=True,verbose_name='电影评分')
    cover_url = models.URLField(null=True)
    run_time = models.CharField(max_length=20,null=True,verbose_name='电影时长')
    review_number =models.CharField(max_length=20,null=True,verbose_name='电影点评人数')
    description = models.CharField(max_length=500,null=True,verbose_name='电影介绍')
    is_new = models.CharField(max_length=1,choices=choices,verbose_name='是否热门')
    class Meta:
        db_table = 'douban_movie'

class Comment(models.Model):
    author = models.ForeignKey(Account,related_name='account',on_delete=models.CASCADE,verbose_name='发起评论的人')
    content = models.CharField(max_length=500,verbose_name='评论的内容',null=True)
    created_time = models.DateTimeField(auto_now_add=True,verbose_name='评论发起时间')
    class Meta:
        db_table = 'comment'
        ordering=['-created_time']
    def __str__(self):
        return self.content
#
class Reply(models.Model):
    reply_author = models.ForeignKey(Account,related_name='reply_account',on_delete=models.CASCADE,verbose_name='子评论的人')
    parent_author = models.ForeignKey(Account,related_name='parent_account',on_delete=models.CASCADE,null=True,verbose_name='父评论的人')
    reply_content = models.CharField(max_length=500,verbose_name='回复的内容')
    reply_created_time = models.DateTimeField(auto_now_add=True,verbose_name='评论回复时间')
    comments = models.ForeignKey(Comment,related_name='replyTocomment',on_delete=models.CASCADE,verbose_name='需要回复的评论')
    class Meta:
        db_table = 'reply'
    def __str__(self):
        return self.reply_content

class Behavior(models.Model):
    user = models.ForeignKey(Account,related_name='behavior_account',on_delete=models.CASCADE,verbose_name='点喜欢的人')
    movie = models.ForeignKey(Douban_Movie,related_name='behavior_movie',on_delete=models.CASCADE,verbose_name='点喜欢的电影')
    behavior_like = models.IntegerField(null=True,verbose_name='喜欢')
    behavior_score = models.IntegerField(null=True,verbose_name='评分')

    class Meta:
        db_table='behavior'

